<!DOCTYPE html>
<html>
<head>
	<title>订单列表</title>
	<include file='public/head'>
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;}
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
	</style>
</head>
<body>
<!-- layui-tab开始 -->
<div class="layui-tab " lay-filter="demo-tab">
	<!-- 顶部导航菜单开始 -->
	<div class="layui-tab-nav" >
        <ul class="layui-tab-title">
			{:getNav('order','admin_index/index')};
		</ul>
	</div>
	<!-- 顶部导航菜单结束 -->
	<form class="layui-form table-bar" action="{:cmf_plugin_url('Order://admin_index/index')}" lay-filter="form-bar" method="post" id="ex">
		<div class="layui-form-search-item">
			<br>
			<a href="{:cmf_plugin_url('Order://admin_index/index')}?order_status=" class="layui-btn layui-btn-primary <php>if($order_status == ""){echo "layui-btn-normal";}</php>" >全部订单({$count})</a>
			<a href="{:cmf_plugin_url('Order://admin_index/index')}?order_status=1" class="layui-btn layui-btn-primary <php>if($order_status == "1"){echo "layui-btn-normal";}</php>">待付款({$count1})</a>
			<a href="{:cmf_plugin_url('Order://admin_index/index')}?order_status=2" class="layui-btn layui-btn-primary <php>if($order_status == "2"){echo "layui-btn-normal";}</php>" >待发货({$count2})</a>
			<a href="{:cmf_plugin_url('Order://admin_index/index')}?order_status=3" class="layui-btn layui-btn-primary <php>if($order_status == "3"){echo "layui-btn-normal";}</php>" >已发货({$count3})</a>
			<a href="{:cmf_plugin_url('Order://admin_index/index')}?order_status=4" class="layui-btn layui-btn-primary <php>if($order_status == "4"){echo "layui-btn-normal";}</php>" >已完成({$count4})</a>
			<a href="{:cmf_plugin_url('Order://admin_index/index')}?order_status=5" class="layui-btn layui-btn-primary <php>if($order_status == "5"){echo "layui-btn-normal";}</php>" >已关闭({$count5})</a>
			<br>
		</div>
	<!-- 搜索栏开始 -->
	<fieldset class="layui-elem-field layui-field-title layui-field-padding">
		<legend class="layui-legend-size">搜索</legend>
			<div class="layui-form-search-item">
				{$searchStr}
				<button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
			</div>
		</form>
	</fieldset>
	<!-- 搜索栏结束 -->
	<div class="layui-card">
		<!-- 表格内容开始 -->
		<div class="layui-card">
			<div class="layui-card-header layui-bg-gray layui-bottom">
				<a href="javascript:;" class="layui-btn layui-btn-xs add-btn" onclick="exportAll()"><i class="layui-icon">&#xe67d;</i>订单导出</a>
				<?php
					if($order_status == 2){
				?>
					<a href="javascript:;" class="layui-btn layui-btn-xs add-btn" onclick="allSend()"><i class="layui-icon">&#xe66d;</i>批量发货</a>
				<?php
					}
				?>
			</div>
			<div class="layui-card-body layui-nopadding " >
				<table  class="layui-table layui-nomargin" >
					<!-- 表格头 -->
					<thead>
						<tr>
							<th width='20px'>
								<input type='checkbox' id='check-box-all' class='layui-form-checkbox'>
							</th>
							<php>
								//输出表格头
								echo $table->getHeader();
							</php>
							<th>操作</th>
						</tr>
					</thead>
					<!-- 表格头 -->
					<!-- 表格内容输出 -->
					<form method="post" id="f">
					<volist name="list" id="vo">
						<tr>
							<th>
								<input type="checkbox" class='check-box' name='order_num[]' value='{$vo.order_num}'>
							</th>
							<php>
								echo $table->createHtml($vo);
							</php>
<!-- <a href="javascript:;" class="layui-btn layui-btn-xs add-btn" onclick="allSend()"><i class="layui-icon">&#xe66d;</i>批量发货</a> -->
							<td width="120px">
								<!-- <if condition="$vo['order_status'] == 2">
									<a type='button' class='layui-btn layui-btn-xs layui-btn-primary detail-btn send-btn' style='font-weight:800 ;' data-id='{$vo.order_num}' title='发货'>
										<i class='layui-icon'>&#xe66d;</i>
									</a>
								</if> -->
								<a href="{:cmf_plugin_url('Order://admin_index/orderDetail')}?order_num={$vo.order_num}" type='button' class='layui-btn layui-btn-xs layui-btn-primary detail-btn' style='font-weight:800 ;' data-id='{$vo.order_num}' title='查看'><i class='layui-icon'>&#xe602;</i></a>
							</td>
						</tr>
					</volist>
					</form>
					<!-- 表格内容输出结束 -->
				</table>
	               <div class="layui-table-page">
	                    <div id="layui-table-page1">
	                        <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
	                            {$list->render([10,20,30,50,100,500])|default=''}
	                        </div>
	                    </div>
	                </div>
			</div>
		</div>
		<!-- 表格内容结束 -->
	</div>
</div>
	<include file='public/scripts'>
<script type="text/javascript">
	//全选/取消
	$('#check-box-all').on('click',function(){
		$('.check-box').prop('checked',$('#check-box-all').prop('checked'));
	});
	//发货
	$('.send-btn').on('click',function(){
		let id = $(this).data('id');
		let url = "{:cmf_plugin_url('Order://admin_index/send')}";
		var text = "确定要发货吗？";
        layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
            $.ajax({
            	type:'post',
                url:url,
                data:{'order_num':id},
                success:function(data){
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:1,time:1500},function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg,{icon:2,time:1500});
                    }
                },
                error:function(){
                    layer.msg('系统错误',{icon:2,time:1500});
                }
            })
        },function(index){
            // alert('取消');
        });		
	})
	//批量发货
    function allSend(){
        var text = "确定要全部发货吗？";
        var da = $('#f').serialize();
        let url = "{:cmf_plugin_url('Order://admin_index/send')}";
        layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
	        if(da == ''){
	        	layer.msg('请先选择订单');
	        	return false;
	        }
            $.ajax({
            	type:'post',
                url:url,
                data:da,
                success:function(data){
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:1,time:1500},function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg,{icon:2,time:1500});
                    }
                },
                error:function(){
                    layer.msg('系统错误',{icon:2,time:1500});
                }
            })
        },function(index){
            // alert('取消');
        });
    }	
    //批量导出
    function exportAll(){
        var text = "将导出当前筛选的订单";
        var da = $('#ex').serialize();
        let url = "{:cmf_plugin_url('Order://admin_index/index')}?export=1";
        layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
	        if(da == ''){
	        	layer.msg('请先选择订单');
	        	return false;
	        }
	       	$('#ex').attr('action',url);
	        $('#ex').submit();
	        $('#ex').attr('action','');
	        layer.closeAll();
        },function(index){
            // alert('取消');
        });
    }
</script>
</body>
</html>